package hw2.cs236369.parsing;

import hw2.cs236369.interfaces.IAuthor;
import hw2.cs236369.interfaces.IPaper;

import java.util.Collection;

/**
 * Paper class, implements IPaper.
 * 
 * @author gil
 * 
 */
public class Paper implements IPaper {
	private Collection<IAuthor>	_authors;			//authors who wrote the paper
	private final int			_publicationYear;	//paper's publication year

	/**
	 * Create a new paper.
	 * 
	 * @param publicationYear Paper's publication year
	 * @param authors Paper's owners
	 */
	public Paper(int publicationYear, Collection<IAuthor> authors) {
		_publicationYear = publicationYear;
		_authors = authors;
	}

	@Override
	public Collection<IAuthor> getAuthors() {
		return _authors;
	}

	@Override
	public int getPublicationYear() {
		return _publicationYear;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((_authors == null) ? 0 : _authors.hashCode());
		result = prime * result + _publicationYear;
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof Paper)) {
			return false;
		}
		Paper other = (Paper) obj;
		if (_authors == null) {
			if (other._authors != null) {
				return false;
			}
		} else if (!_authors.equals(other._authors)) {
			return false;
		}
		if (_publicationYear != other._publicationYear) {
			return false;
		}
		return true;
	}


}
